<template>
  <div class="page">
    <!-- <div class="s-search p20">
      <el-form
        :model="alone.searchForm.data"
        status-icon
        ref="ruleForm"
        :inline="true"
        class="demo-ruleForm"
      >
        <el-form-item>
          <el-button
            icon="iconfont iconpailie"
            :type="showPrimary('time1')"
            @click="rChangeSearchOrderBy('time1')"
            >提交人数排序</el-button
          >
        </el-form-item>
      </el-form>
    </div> -->

    <div class="c-main p20">
      <!-- <div class="c-aside clearfix">
        <el-button
          type="primary"
          class="fr btn"
          @click="rDownloadClueActor"
          v-hasAuth:seestar_clueActorListExport
          >导出主播线索</el-button
        >
      </div> -->
      <div class="c-section">
        <div class="c-body">
          <el-table :data="pageAjax.data" stripe style="width: 100%">
            <el-table-column prop="nickName" label="类型">
              <template slot-scope="scope">
                <div class="">
                  {{ TYPE[scope.row.type] }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="类别">
              <template slot-scope="scope">
                <div class="">
                  {{ SUBTYPE[scope.row.subType] }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="资料提交页浏览次数(次)">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.count || "无" }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  v-hasAuth:seestar_channelH5SubmitVisitorByDate
                  @click="rDetail(scope.row.channelMaterialId)"
                  >详情</el-button
                >
                <span v-hasAuth:seestar_channelH5SubmitVisitorByDate.invert
                  >—</span
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- <div class="c-footer">
          <div class="c-pagination">
            <el-pagination
              layout="prev, pager, next"
              @current-change="rPagingChange"
              @prev-click="rPagingChange"
              @next-click="rPagingChange"
              :current-page="pageAjax.paging.current"
              :total="pageAjax.paging.total"
            >
            </el-pagination>
          </div>
        </div> -->
      </div>
    </div>
    <!-- detailDrawerCp -->
    <el-drawer
      :title="detailDrawerCp.config.title"
      :visible.sync="detailDrawerCp.config.visible"
      :direction="detailDrawerCp.config.direction"
      :size="detailDrawerCp.config.size"
    >
      <div class="f-detailDrawerCp">
        <div class="n-content">
          <el-row type="flex" justify="center">
            <el-col :span="18" :offset="3">
              <el-table :data="vewCountByDate.data" style="width: 100%">
                <el-table-column prop="date" label="日期" width="width" />
                <el-table-column prop="count" label="浏览量" width="width" />
              </el-table>
              <div class="c-footer">
                <div class="c-pagination">
                  <el-pagination
                    layout="prev, pager, next"
                    @current-change="rPagingChange"
                    @prev-click="rPagingChange"
                    @next-click="rPagingChange"
                    :current-page="vewCountByDate.paging.current"
                    :total="vewCountByDate.paging.total"
                  >
                  </el-pagination>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-drawer>
  </div>
</template>
<script>
import {
  getMaterialViewCount,
  getMaterialViewCountByDate
} from "@/api/channel.js";
import { mixin } from "@/components/mixin/getSalaryStr.js";
import _ from "lodash";

const TYPE = {
  "1": "二维码",
  "2": "H5"
};

const SUBTYPE = {
  YUJIA_QRCODE: "娱加小程序二维码",
  YUJIA_XIAOJINLI_QRCODE: "小锦鲤-青云团队二维码",
  YUJIA_H5: "娱加H5",
  YUJIA_XIAOJINLI_H5: "小锦鲤-青云团队H5"
};

export default {
  name: "seestar_channelH5SubmitVisitor",
  mixins: [mixin],
  data: () => ({
    TYPE,
    SUBTYPE,
    pageAjax: {
      btnDisabled: false,
      btnLoading: false,
      loading: false,
      lock: false,
      paging: {
        pages: 1, // 总页数
        current: 0, // 当前页
        total: 1, // 总数量
        pageSize: 10 // 每页数量
      },
      data: []
    },
    vewCountByDate: {
      id: "",
      paging: {
        pages: 1, // 总页数
        current: 0, // 当前页
        total: 1, // 总数量
        pageSize: 10 // 每页数量
      },
      data: []
    },
    alone: {
      searchForm: {
        loading: false,
        data: {
          channelId: ""
        }
      },
      signStatus: "POTENTIAL"
    },
    detailDrawerCp: {
      config: {
        title: "",
        visible: false,
        direction: "ttb",
        size: "90%"
      },
      data: {}
    }
  }),
  created() {
    let _that = this;
    if (this.$route.query && this.$route.query.channelId > -1) {
      this.alone.searchForm.data.channelId = this.$route.query.channelId;
    }
    _that.getPageData();
  },
  methods: {
    rChangeSearchOrderBy(val) {
      this.alone.searchForm.data.orderBy = val;
    },
    showPrimary(val) {
      if (this.alone.searchForm.data.orderBy == val) {
        if (this.alone.searchForm.data.order == "desc") {
          return "success";
        } else {
          return "primary";
        }
      }
      return "default";
    },
    rDetail(id) {
      let _that = this;
      this.vewCountByDate.id = id;
      this.detailDrawerCp.config.visible = true;
      if (_that.pageAjax.loading) {
        return;
      }

      _that.pageAjax.lock = false;
      _that.pageAjax.paging.current = 0;
      _that.getVewCountByDateData();
    },

    rPagingChange(e) {
      let _that = this;
      _that.vewCountByDate.paging.current = e - 1;
      _that.getVewCountByDateData();
    },

    getPageData() {
      let _that = this;
      let searchForm = _.cloneDeep(_that.alone.searchForm);
      let pageAjax = _that.pageAjax;

      if (pageAjax.loading || pageAjax.lock) {
        return;
      }

      let data = { ...searchForm.data };
      data.pageNo = _that.pageAjax.paging.current + 1;
      _that.pageAjax.loading = true;
      getMaterialViewCount({ params: data })
        .then(resp => {
          let respData = resp.data || {};

          if (respData.code === _that.STATUS.success[0]) {
            _that.pageAjax.data = respData.data;
          } else {
            _that.$message.error(respData.msg || "获取失败");
          }
        })
        .finally(() => {
          _that.pageAjax.loading = false;
        });
    },

    getVewCountByDateData() {
      const data = {
        channelMaterialId: this.vewCountByDate.id,
        pageNo: this.vewCountByDate.paging.current,
        pageSize: this.vewCountByDate.paging.pageSize
      };
      getMaterialViewCountByDate({ params: data }).then(res => {
        this.vewCountByDate.data = res.data.data.list;
        this.vewCountByDate.paging = res.data.data.pagination;
      });
    },
    rToUrl() {
      this.$router.push({ name: "seestar_create" });
    },
    navToEdit(id) {
      this.$router.push({
        name: "seestar_channelClueEdit",
        query: {
          anchorId: id
        }
      });
    },
    navToDetail(id) {
      this.$router.push({
        name: "seestar_channelClueDetail",
        query: {
          anchorId: id
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.page {
  .s-search {
    border-bottom: 1px solid #eee;
  }
  .c-aside {
    .btn {
      margin-right: 20px;
    }
    .diy-uploadBtn {
      margin-right: 20px;
    }
  }
  .c-main {
    margin-top: 20px;
    .c-avatar {
      display: block;
      width: 100px;
      height: 100px;
      border-radius: 50%;
    }
  }
  .c-pagination {
    margin-top: 20px;
    text-align: center;
  }
  .f-record {
    overflow: hidden;
    position: absolute;
    width: 100%;
    left: 0;
    top: 50px;
    bottom: 0;
    .c-content {
      height: 100%;
      padding-bottom: 20px;
      overflow: auto;
    }
  }
  .f-detailDrawerCp {
    overflow: hidden;
    position: absolute;
    width: 100%;
    left: 0;
    top: 50px;
    bottom: 0;
    .n-content {
      height: 100%;
      padding: 30px 0;
      overflow: auto;
      box-sizing: border-box;
    }
    .n-note {
      line-height: 2;
      color: #999;
    }
  }
  .f-agent {
    overflow: hidden;
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
    bottom: 0;
    .c-content {
      height: 100%;
      padding-bottom: 20px;
      padding-top: 60px;
      overflow: auto;
    }
    .c-avatar {
      width: 80px;
      height: 80px;
    }
  }
}
</style>
